package com.ruyuan2020.im.xx.xxx;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author gaowei
 * @date 2025/3/5
 */
public class MyCASExample {
    private AtomicInteger count = new AtomicInteger(0);

    public void increment() {
        int expectedValue, newValue;
        do {
            expectedValue = count.get();
            newValue = expectedValue + 1;
        } while (!count.compareAndSet(expectedValue, newValue));
    }

    public int getCount() {
        return count.get();
    }

}